<template>
  <div>
    <div style="margin-top: 10px; padding: 5px">
      <table class="table-layout" :style="tableWidth">
        <tbody>
          <tr v-for="(tr, trIndex) in layoutArray" :key="trIndex" :style="trHeight">
            <fancy-edit-table-item
              v-for="(td, tdIndex) in tr"
              :key="tdIndex"
              :item="td"
              :td-index="tdIndex"
              :tr-index="trIndex"
              :td-style="tdStyle"
            >
              <slot :td="td" />
            </fancy-edit-table-item>
          </tr>
        </tbody>
      </table>
    </div>
  </div>
</template>

<script>
  import fancyEditTableItem from './fancyEditTableItem.vue';
  export default {
    name: 'FancyEditTable',
    components: {
      fancyEditTableItem,
    },
    props: {
      layoutArray: {
        type: Array,
        default: () => [],
      },
      tdStyle: {
        type: String,
        default: '',
      },
      width: {
        type: Number,
        default: 100,
      },
      height: {
        type: Number,
        default: 100,
      },
    },
    data() {
      return {};
    },
    computed: {
      tableWidth() {
        return `width:${this.width}%`;
      },
      trHeight() {
        return `height:${this.height}px`;
      },
    },
    mounted() {},
    unmounted() {},
    methods: {},
  };
</script>

<style scoped>
  table {
    width: 100%;
    border-spacing: 0;
  }

  tbody {
    display: table-row-group;
    border-color: inherit;
    vertical-align: middle;
  }

  td {
    border: 1px #d2d2d2 solid;
  }

  .table-layout {
    width: 100%;
    margin: 0 auto;
    padding: 8px !important;
    table-layout: fixed;
    border-collapse: collapse;
    background-color: #fff;
    text-align: left;
  }

  .table-layout > tbody > tr > td {
    height: 20px;
    padding: 6px;
    border: 1px solid #d2d2d2;
    word-break: break-word;
  }

  .table-layout > tbody > tr {
    border-top: 1px solid #d2d2d2;
    border-bottom: 1px solid #d2d2d2;
  }

  .right-menu {
    position: fixed;
    z-index: 100;
    width: 200px;
    padding: 8px 0;
    border: 1px solid #ccc;
    border-radius: 3px;
    background-color: #fff;
    box-shadow: 3px 3px 8px #999;
  }

  .right-menu ul {
    margin: 0;
    padding: 0;
  }

  .right-menu ul li {
    height: 30px;
    padding: 0 15px;
    line-height: 30px;
  }

  .right-menu ul li:hover {
    background-color: #ccc;
    cursor: pointer;
  }

  .CellHide {
    display: none;
  }
</style>
